home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / vdtj122b.zip / WILDFILE.VDM < prev    next >
Text File  |  1992-11-13  |  6KB  |  214 lines

  1. !    WILDFILE.VDM Macro
  2. !
  3. ! Runs any VEDIT command or another macro on an entire group of files.
  4. !
  5. ! Register Usage:
  6. !
  7. !      Y        Break-out/exit macro
  8. !    Q80        User's last choice
  9. !    Q81        Value of parent auto-execution macro
  10. !    Q82        T-Reg # containing this macro
  11. !    Q83        Original edit buffer #
  12. !    Q88        Original ES 8 value
  13. !    Q89        ES 9 value
  14. !    Q90        Edit-buffer # for editing each file
  15. !    Q91        Edit-buffer # for holding main macro
  16. !    Q92        T-Reg # for holding macro executed for each file
  17. !    Q93        T-Reg # for holding search string
  18. !    Q94        T-Reg # for holding replace string; temp filenames
  19. !    Q97        Flag - pause after each file
  20. !    Q98        Flag - break-out operation
  21. !    Q99        Flag - 1987654321 when macro is running
  22. !
  23. !****************************************************************************
  24. R*
  25. R*    Init -    1) Save state; set desired ES values
  26. R*        2) Determine free edit buffers/T-Regs
  27. R*        3) Setup Y with Break-out/exit (auto-execute) macro
  28. R*
  29. (Q99=1987654321)@JP"LABEL1"    R* Skip init if macro already running
  30. XPUSH(80,99)            R* Save numeric regs
  31. .raXS(81)            R* Q81 = parent's auto-execution (0=none)
  32. .mnXS(82)            R* #82 = T-Reg containing this macro
  33. .bnXS(83)            R* #83 = original edit buffer
  34. ES 8 1 .rvXS(88)        R* Save original ES values; set new ones
  35. ES 9 1 .rvXS(89)
  36.  
  37. .bfXS(90) EE(#90)        R* #90 = buffer for editing files
  38. .bfXS(91) @EE(#91)        R* #91 = buffer for main macro
  39. .bfXS(92) RI(#92)" "        R* #92 = Reserve T-reg for sub-macro
  40. .bfXS(93) RI(#93)" "        R* #93 = Reserve T-Reg for search string
  41. .bfXS(94) RI(#94)" "        R* #94 = Reserve T-Reg for replace string
  42.  
  43. R*
  44. R*****  Macro Y catches break-outs and exits macro
  45. R*
  46. RI(y)~
  47. .ws(z)>0[ YWD(z) ]
  48. (.ed & Q11=-1)_JP"EXIT"        R* Exit if VDEMO and demo macro are running
  49. YEN
  50. Q98=1[ YA YT"BREAK-OUT!" ]
  51. YT"
  52. 1) Run WILDFILE again
  53. 2) Exit macro, return to VEDIT
  54. 3) Exit VEDIT (save/abandon files)
  55.  
  56. Enter desired option: "
  57.  
  58. [ XK(0)"" ("0<Q0 & Q0<"4)JL YA ] Q0:YD        R* Get valid reply
  59.  
  60. -EE(#91) EZY -EE(#90)
  61. (Q0=="1)[ RJ(#82) ]
  62. (Q0=="3)[ EXX RJ(#82) ]
  63.  
  64. !EXIT!
  65. ES 8 Q88            R* Restore state before returning
  66. ES 9 Q89
  67. -EE(#90) EQY -EE(#91) EQY RE(#92) RE(#93) RE(#94)
  68. -EE(#83)            R* Return to original edit buffer
  69. +RA(#81) -YYA
  70. XPOP(80,99)            R* Restore numeric regs
  71. .ra>0[ JM ][ +JO ]
  72. ~
  73.  
  74. R*
  75. R*    Main Body of Macro...
  76. R*
  77. !LABEL1!
  78. 1XS(98)            R* Enable "BREAKOUT" message
  79. 1987654321XS(99)    R* Macro is now running
  80. +RA(Y) YYA        R* Enable Break-out macro
  81.  
  82. EE(#91)    EZY        R* Switch to main macro and clear it
  83. YEC
  84. YT"
  85.                 *****************************************
  86.                 *                                       *
  87.                 *       WILDFILE.VDM - 11/12/92         *
  88.                 *        Multi-file Processing          *
  89.                 *                                       *
  90.                 *****************************************
  91.  
  92. Enter the names of the files you want to operate on and <Enter>.
  93. (The wildcards '?' and '*' may be used).
  94.  
  95. Press <Enter> twice when done.
  96.  
  97. "
  98. R*
  99. R*    Prompt for filenames and expand wildcards; add complete pathname.
  100. R*
  101. #[
  102. !FLOOP!
  103. :RQ(#94)"Enter filename: " (.u#94=0)_JL
  104. :ED|R#94            !Test if file(s) exist (.rv==0 if not)
  105. (.rv=0)[ YT"File(s) not found.  Try again." YEN JP"FLOOP" ]
  106. Z .pXS(0)            !Goto end of buffer and save position
  107. YI 1ED|R#94 -YI            !Insert directory into edit-buffer #91
  108. Q0EJ                !Restore position
  109. N"Directory "            !Search for "Directory" header
  110. -K                !Delete partial header and previous blank line
  111. .pXS(0)                !Save current position
  112. $N"|>"                !Advance to end of line
  113. Q0,.pRC(#92)            !Copy drive:pathname to T-Reg #92
  114. 0KK                !Delete rest of header
  115. !
  116. !    Cleanup filenames.
  117. !
  118. B #[ $N"|<|>" ; 0KK ]        !Remove blank lines
  119. B #$S"|W""            !Eliminate excess white space (in filenames)
  120. B #[ $N".." ; 0KK ]        !Remove the ".." entry
  121. (.os<4)[            !DOS uses "\", UNIX/QNX use "/"
  122.     B #[ $N"\|>" ; 0KK ]    !Remove "\" sub-directory entries
  123.     ][
  124.     B #[ $N"/|>" ; 0KK ]
  125.     ]
  126. Q0EJ                !Restore position
  127. #[
  128.     $N"|<|X" ; -C +RG(#92)     !Precede each filename with full drive:pathname
  129.     (.os<4)[ I"\" ][ I"/" ]    !DOS needs "\"; UNIX/QNX need "/"
  130.     ]
  131. ]
  132. R*
  133. R*    Prompt for desired operation.
  134. R*
  135. #[
  136.     YEN XK(80)\Execute a [C]ommand, [M]acro, [S]earch or [R]eplace? \
  137.     Q80&223 XS(80) ((Q80="C)^(Q80="M)^(Q80="S)^(Q80="R))_JL YA
  138.     ]
  139.  
  140. (Q80="C)[ 2YEN :RQ(#92)"Enter command: "
  141.     ][
  142. (Q80="M)[
  143.     2YEN :RQ(#94)"Enter filename of macro: "
  144.     +RL(#92) |R#94
  145.     ][
  146.     2YEN :RQ(#93)"Enter search string: "
  147.     !
  148.     ! Build macro in current edit buffer, 91EI and 93EI create brackets
  149.     ! Use 255(decimal) as explicit delimiters
  150.     !
  151.     (Q80="S)[
  152.         EE(#90) EZY 91EI I"@_F" 255EI +RG(#93) 255EI
  153.         ][
  154.         YEN :RQ(#94)"Enter replace string (and Enter): "
  155.         EE(#90) EZY 91EI I"@_S" 255EI +RG(#93) 255EI +RG(#94) 255EI
  156.         ]
  157.     #[
  158.         YEN XK(80)\[D]isplay line or enter [V]isual Mode? \
  159.         Q80&223 XS(80) ((Q80="D)^(Q80="V))_JL YA
  160.         ]
  161.  
  162.     (Q80="D)[
  163.         I" @YT\LINE:\ .lnXS(80) :XT(80) 2YEB 0TT" 93EI
  164.         ][
  165.         I"V" 93EI
  166.         ]
  167.     -#RC(#92) EZY EE(#91)        !Copy to register #92 and clear edit buffer
  168.     ]
  169.     ]
  170. R*
  171. R* If not "[V]isual Mode", prompt whether to pause after each file.
  172. R*
  173. (Q80="V)[
  174.     0XS(97)
  175.     ][
  176.     #[
  177.         YEN XK(97)\Should macro pause after each file is processed? [Y]es [N]o \
  178.         Q97&223 XS(97) ((Q97="Y)^(Q97="N))_JL YA
  179.         ]
  180.     ]
  181. R*
  182. R*    Expand each filename line into full macro command.
  183. R*    YQ filename .rvXS(100) Q100=0[ EE(#90) EB filename<ESC> 
  184. R*    YEN @YT\...Processing \ :EW 2YEN M(#92) :EY ][
  185. R*    EE(#100) YYP YEN @YT\...Processing \ :EW 2YEN B M(#92) YYO ]
  186. R*    Q97="Y[ +@XK(100)\Press any key to continue...\ ]
  187. R*
  188. RI(#93)\YQ |R#94 .rvXS(100) Q100=0[ EE(#90) EB |R#94 YEN @YT"...Processing " :EW 2YEN M(#92) :EY ][ EE(#100) YYP YEN @YT"...Processing " :EW 2YEN B M(#92) YYO ] Q97="Y[ +@XK(100)"Press any key to continue..." ]\
  189. B
  190. #[
  191.     .eof_JL
  192.     I/RI(#94)"/
  193.     $N"|>"
  194.     I/" M(#93)/
  195.     :L
  196.     ]
  197. EE(@)
  198. YEN XK(100)"Press any key to begin operation..."
  199.  
  200. .wt>1[ YWI ]        R* Delete any windows
  201. ES 9 Q89
  202.  
  203. (Q80="V)[
  204.     (.wb=2)[ 0YWB(z) 1 ][ YWB(z) 1 ]
  205.     YWS(z)
  206.     112YEA YEC
  207.     YT"    Press [VISUAL EXIT] (<Ctrl-E>) to search for next occurrence."
  208.     YWS(@)
  209.     ]
  210.  
  211. M(#91)            R* Perform desired operation on all files
  212. 0XS(98)            R* Disable "BREAK-OUT" message
  213. RJ(Y)            R* Chain to Break-out/exit macro
  214.